#include "db/indexarray.hxx"
#include <iostream>
#include <stdlib.h>

void printHeader(IndexArrayHeader& h) {
    std::cout<<"Header: "<<std::endl;
    std::cout<<h.toString()<<std::endl;
}


void printIndex(IndexArrayFile& f) {
    int length = f.getHeader().getArrayLength();

    for(int i = 0; i < length; ++i) {
        std::cout<<i<<"  "<<f.get(i)<<std::endl;
    }
}

DbStatus printArray(const std::string& indexFile) {
    DbStatus ret;

    IndexArrayFile f(indexFile);
    ret = f.init();
    if(!ret.isok()) return ret;
  
    IndexArrayHeader h = f.getHeader();
    printHeader(h);

    printIndex(f);

    return ret;
}


void usage() {
    std::cout<<"indexarrayprint <index file path>"<<std::endl;
    exit(-1);
}


int main(int argc, char** argv) {
    if(argc != 2) usage();

    DbStatus ret = printArray(argv[1]);
    if(!ret.isok()) std::cout<<ret.msg()<<std::endl;
}

